package com.esl.action.admin;

import java.util.Map;
import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.stereotype.Controller;

import com.esl.action.CommonAction;
import com.esl.dto.admin.User_Dto;
import com.esl.model.admin.User;
import com.esl.service.admin.UserManager;

//@Controller
@Results({ @Result(name = "tolist", location = "user?jump_url=list", type = "redirect") })
public class UserAction extends CommonAction {

	private Map<String, Object> session = getSession();
	private User_Dto user_Dto = new User_Dto();
	private UserManager userManager;

	public String updatePassword() {
		User user = userManager.getUserByID(getUid());
		if (user_Dto.passwordEqual(user.getPassword())) {
			user.setPassword(user_Dto.getPassword());
			userManager.update(user);
			return "toIndex";
		} else
			return "error";
	}

	public String updateDetail() {
		return "index";
	}

	public String load() {
		setPageInfo_Dto(userManager.load(1, 2, "", ""));

		return "success";
	}

	// 用户注册,注册成功返回登陆界面，注册失败返回到注册页面
	public String register() {
		if (userManager.checkStudentNo(user_Dto.getStudentNO())) {
			userManager.add(user_Dto.toUser());
			return "toLogin";
		}
		return "toRegister";
	}

	/*--------------------------------*/
	public User_Dto getUser_Dto() {
		return user_Dto;
	}

	public void setUser_Dto(User_Dto user_Dto) {
		this.user_Dto = user_Dto;
	}

	/*--------------------------------*/
	@Resource
	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}

	@Resource
	public void setUserManger(UserManager userManager) {
		this.userManager = userManager;
	}

}
